package com.example.anew.journey.mynewjourney.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.example.anew.journey.mynewjourney.utils.MyDpToPxUtils;

/**
 * 杭州惟君医疗科技有限公司17
 * Created by 20433 on 2018/3/20
 */

public class MyCenterLineView extends View {
    private int YoffSet = 60;  //y轴的偏移量
    private Paint mpaint;
    private int mCenterLinecolor = 0xff1E90FF; //线的颜色
    private int controlswidth;
    private int controlsheight;
    private int XoffSet = 100; //x轴偏移量
    private Context mcontext;
    private Paint tpaint;

    public MyCenterLineView(Context context) {
        this(context,null);
    }

    public MyCenterLineView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public MyCenterLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mcontext =context;
        init();
    }

    private void init() {
        mpaint = new Paint();
        mpaint.setAntiAlias(true);
        mpaint.setStyle(Paint.Style.STROKE);
        mpaint.setColor(mCenterLinecolor);
        mpaint.setStrokeWidth(3);

        tpaint = new Paint();
        tpaint.setAntiAlias(true);
        tpaint.setStyle(Paint.Style.STROKE);
        tpaint.setColor(0xff666666);
        tpaint.setTextSize(20);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        controlswidth = w;
        controlsheight = h;
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //画线
        canvas.drawLine(MyDpToPxUtils.dp2px(mcontext,60)+XoffSet*3,controlsheight-YoffSet,MyDpToPxUtils.dp2px(mcontext,60)+XoffSet*3,YoffSet,mpaint);
        // 画文字
        canvas.drawText("正常范围",controlswidth - MyDpToPxUtils.dp2px(mcontext,65),YoffSet/2,tpaint);
    }
}
